﻿using otis.entities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;

// “空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234238 上有介绍

namespace otis
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class PageHistory : Page
    {
        

        public PageHistory()
        {
            this.InitializeComponent();


            this.lvYear.ItemsSource = this.InitYears();
            
            this.InitProjects();


            this.lvYear.SelectedIndex = 0;
            this.lvYear.SelectedItem = "1990";
        }


        private void LoadGridView(int year)
        {
            foreach (BigThing item in this.InitProjects()) {
                if (item == null) continue;
                this.txtTitle.Text = item.Title;
//                this.imagePath.Source = new BitmapImage(new Uri(item.ImagePath));
                //this.imagePath.Source = new BitmapImage(new Uri("/images/02.jpg",UriKind.Relative));
                this.imagePath.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx://"+"/images/02.jpg", UriKind.RelativeOrAbsolute));
            }
        }


        private List<int> InitYears()
        {
            var years = new List<int>();
            for (int i = 1990; i <= 2014; i++) {
                years.Add(i);

            }

            return years;
        }


        private List<BigThing> InitProjects()
        {
            var years = this.InitYears();



            var bigThings = new List<BigThing>();
            foreach (int item in years) {
                bigThings.Add(new BigThing() { ImagePath = "images/02.jpg", year = item, Title = System.Guid.NewGuid().ToString("N") });
            }
            return bigThings;

        }

        private void lvYear_ItemClick(object sender, ItemClickEventArgs e)
        {
            int year = int.Parse(e.ClickedItem.ToString());
            this.LoadGridView(year);
        }

        private void btnHome_Click(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(MainPage));
        }
    }
}
